set more off
use "Data/Survivial", clear

egen gID           = group(ID)
egen gDate         = group(Date)
egen gCompany      = group(Company)
egen gCompanyxDate = group(Company Date)

global basevar  c.NearSubway#c.Post NearSubway Post
global controls adjage_yrs adjexp_mnths Education NChild Male /*
*/ Manager Distance i.gCompany Married NewEmployeeD

global exp_cubic  c.adjexp_mnths##c.adjexp_mnths##c.adjexp_mnths
global age_cubic  c.adjage_yrs##c.adjage_yrs##c.adjage_yrs 
global tenure_5th c.adjtenure_mnths##c.adjtenure_mnths##c.adjtenure_mnths##c.adjtenure_mnths##c.adjtenure_mnths


stset Date, failure(exitd == 1) id(ID) origin(time FirstMonth) enter(time EntMonth)

stcox $basevar $controls, nohr  vce(cl gID)
outreg2 using "Output/Table4.xls", dec(2)  replace ctitle(Cox) addstat(Log Likelihood, e(ll), $chi2 Test, e(chi2)) addtext(Controls, Yes, SE Clustered By, ID, Cubic in Age and Exp, No)

streg $basevar $controls, nohr  vce(cl gID) dist(exponential)
outreg2 using "Output/Table4.xls", dec(2)  append  ctitle(Exp) addstat(Log Likelihood, e(ll), $chi2 Test, e(chi2)) addtext(Controls, Yes, SE Clustered By, ID, Cubic in Age and Exp, No)

stcox $basevar $controls $exp_cubic $age_cubic, nohr  vce(cl gID)
outreg2 using "Output/Table4.xls", dec(2)  append  ctitle(Cox) addstat(Log Likelihood, e(ll), $chi2 Test, e(chi2)) addtext(Controls, Yes, SE Clustered By, ID, Cubic in Age and Exp, Yes)

streg $basevar $controls $exp_cubic $age_cubic, nohr  vce(cl gID) dist(exponential)
outreg2 using "Output/Table4.xls", dec(2)  append  ctitle(Exp) addstat(Log Likelihood, e(ll), $chi2 Test, e(chi2)) addtext(Controls, Yes, SE Clustered By, ID, Cubic in Age and Exp, Yes)


reghdfe exitd $basevar $controls, absorb(gCompanyxDate) vce(cl gID gDate)
outreg2 using "Output/Table4.xls", dec(3)  append addstat(Adj R-sq, e(r2_a)) addtext(Controls, Yes, SE Clustered By, ID and month, Cubic in Age and Exp, No, Individual FE, No, Company-Year-Month FE, Yes)

reghdfe exitd $basevar $controls $exp_cubic $age_cubic $tenure_5th , absorb(gCompanyxDate) vce(cl gID gDate)
outreg2 using "Output/Table4.xls", dec(3)  append addstat(Adj R-sq, e(r2_a)) addtext(Controls, Yes, SE Clustered By, ID and month, Cubic in Age and Exp, Yes, Individual FE, No, Company-Year-Month FE, Yes)

